//
//  WHLoginView.m
//  WHPersonalData
//
//  Created by shengmeng chen on 2021/7/28.
//  Copyright © 2021 mac. All rights reserved.
//

#import "WHLoginView.h"
#import "SVProgressHUD.h"
#import <sys/utsname.h>
#import "CommonTools.h"
#import "SDAutoLayout.h"


@interface WHLoginView ()

/**    手机号  */
@property (nonatomic,weak)UITextField*iphoneTF;
/**    手机号  */
@property (nonatomic,weak)UILabel *iphoneLabel;
/**    密码  */
@property (nonatomic,weak)UITextField *passwordTF;
/**    密码 */
@property (nonatomic,weak)UILabel *passwordLabel;

/**    姓名  */
@property (nonatomic,weak)UITextField *nameTF;
/**   姓名 */
@property (nonatomic,weak)UILabel *nameLabel;

/**    登录  */
@property (nonatomic,weak)UIButton *loginButton;
/**    忘记密码  */
@property (nonatomic,weak)UIButton*forgetPassword;

@property(nonatomic,retain)NSString*wmb_originalProvider; ;

@end

@implementation WHLoginView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpAllChilds];
        
        self.backgroundColor=[UIColor groupTableViewBackgroundColor];
    }
    return self;
}

-(void)setUpAllChilds
{
    /**     手机号  */
    UILabel *iphoneLabel = [[UILabel alloc]init];
    iphoneLabel.text = @"手机号";
    [self addSubview:iphoneLabel];
    
    _iphoneLabel = iphoneLabel;
    
    /**    手机号码  */
    UITextField*iphoneTF =[[UITextField alloc]init];
    iphoneTF.font = [UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
    iphoneTF.placeholder  = @" 手机号";
    iphoneTF.keyboardType = UIKeyboardTypeNumberPad;
    iphoneTF.backgroundColor = [UIColor whiteColor];
    _iphoneTF = iphoneTF;
    [self addSubview:iphoneTF];
    
    UILabel *passwordLabel = [[UILabel alloc]init];
    passwordLabel.text = @"港   号";
    [self addSubview:passwordLabel];
    _passwordLabel = passwordLabel;
    
    /**    密码  */
    UITextField*passwordTF =[[UITextField alloc]init];
    passwordTF.font = [UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
    passwordTF.backgroundColor = [UIColor whiteColor];
    passwordTF.placeholder =@" 港   号";
    [self addSubview:passwordTF];
    _passwordTF = passwordTF;
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.text = @"姓   名";
    [self addSubview:nameLabel];
    _nameLabel = nameLabel;
    
    /**    密码  */
    UITextField*nameTF =[[UITextField alloc]init];
    nameTF.font = [UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
    nameTF.backgroundColor = [UIColor whiteColor];
    nameTF.placeholder =@" 姓   名";

    [self addSubview:nameTF];
    _nameTF = nameTF;
    
    
    //登录
    UIButton *loginButton =[[UIButton alloc]init];
    [loginButton setImage:[UIImage imageNamed:@"登录-登录按钮"]forState: UIControlStateNormal];
    [loginButton setTitle:@"登  录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
    loginButton.backgroundColor = RGBColor(106, 168, 255);
    loginButton.tag =200;
    [loginButton addTarget:self action:@selector(buttonChick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:loginButton];
    _loginButton = loginButton;
    
    //注册
//    UIButton *forgetPwdBtn =[[UIButton alloc]init];
//    [forgetPwdBtn setTitle:@"注    册" forState:UIControlStateNormal];
//    
//    forgetPwdBtn.tag =201;
//    [forgetPwdBtn setTitleColor:RGBColor(165, 165, 165) forState:UIControlStateNormal];
//    [forgetPwdBtn setTitleColor:[UIColor groupTableViewBackgroundColor] forState:UIControlStateHighlighted];
//    
//    [forgetPwdBtn addTarget:self action:@selector(buttonChick:) forControlEvents:UIControlEventTouchUpInside];
//     forgetPwdBtn.titleLabel.font = [UIFont systemFontOfSize:16*WidthScale>20?20:16*WidthScale];
//    
//    [self addSubview:forgetPwdBtn];
//    _forgetPassword = forgetPwdBtn;
    [self setUpLayout];
   
}
-(void)setUpLayout
{
    /**     手机号  */
    _iphoneLabel.sd_layout
    .topSpaceToView(self, kMarginH*10)
    .leftSpaceToView(self,kMarginW*2)
    .widthIs(ScreenW/6)
    .heightIs(kMarginH*3);
    
    _iphoneTF.sd_layout
    .topSpaceToView(self, kMarginH*10)
    .leftSpaceToView(self.iphoneLabel,0)
    .widthIs(ScreenW/1.6)
    .heightIs(kMarginH*3);
    
    _iphoneTF.layer.cornerRadius = 5;
    
    /**   港号  */
    
    _passwordLabel.sd_layout
    .topSpaceToView(self.iphoneLabel, kMarginH*3)
    .leftSpaceToView(self,kMarginW*2)
    .widthIs(ScreenW/6)
    .heightIs(kMarginH*3);
    
    _passwordTF.sd_layout
    .topSpaceToView(self.iphoneLabel, kMarginH*3)
    .leftSpaceToView(self.passwordLabel,0)
    .widthIs(ScreenW/1.6)
    .heightIs(kMarginH*3);
    
    _passwordTF.layer.cornerRadius = 5;
    
    /**   姓名  */
    _nameLabel.sd_layout
    .topSpaceToView(self.passwordLabel, kMarginH*3)
    .leftSpaceToView(self,kMarginW*2)
    .widthIs(ScreenW/6)
    .heightIs(kMarginH*3);
    
    _nameTF.sd_layout
    .topSpaceToView(self.passwordLabel, kMarginH*3)
    .leftSpaceToView(self.nameLabel,0)
    .widthIs(ScreenW/1.6)
    .heightIs(kMarginH*3);
    _passwordTF.layer.cornerRadius = 5;
    
    /**    登录  */
    
    _loginButton.sd_layout
    .topSpaceToView(self.nameLabel, kMarginH*4)
    .centerXEqualToView(self)
    .widthIs(ScreenW/3)
    .heightIs(ScreenH/15);
    _loginButton.layer.cornerRadius = ScreenH/30;
    
}

-(void)getidentifierForVendor{
    
    NSString* identifierNumber = [[UIDevice currentDevice].identifierForVendor UUIDString] ;
    DebugLog(@"手机序列号: %@",identifierNumber);
}
-(void)getVersionCode
{
    //获取手机的型号
    NSString* phoneModel = [CommonTools iphoneType];
    DebugLog(@"phoneModel = %@",phoneModel);
}

-(void)buttonChick:(UIButton*)button
{
        if (button.tag==200)
        {
            if (self.iphoneTF.text.length == 0)
            {
                [SVProgressHUD showSuccessWithStatus:@"手机号不能为空!"];
                DebugLog(@"手机号不能为空!");
                return;
            }
            else if ( self.passwordTF.text.length == 0)
            {
                [SVProgressHUD showSuccessWithStatus:@"港号不能为空"];
                DebugLog(@"港号不能为空!");
                return;
            }
            else if ( self.nameTF.text.length == 0)
            {
                [SVProgressHUD showSuccessWithStatus:@"姓名不能为空"];
                DebugLog(@"姓名不能为空!");
                return;
            }
            //登录
            if(self.clickBtnBlock)
            {
                self.clickBtnBlock(self.iphoneTF.text, self.passwordTF.text, self.nameTF.text);
            }
        }
     else if (button.tag ==201)
     {
         //忘记密码
     }
}


    @end
    
